#!/bin/sh

cd /app

if [ ! -z ${BASE_URL} ]; then
    echo "replace base url with ${BASE_URL}"
    sed -i "s#base href=\"/\"#base href=\"${BASE_URL}\"#g" index.html
fi;

if [ ! -z ${SENTRY_URL_UI} ]; then
    echo "# Inject sentry url variable"
	sed -i -e "s|window.cds_sentry_url = '';|window.cds_sentry_url='${SENTRY_URL_UI}';|g" index.html
    sed -i -e "s|window.cds_version = '';|window.cds_version='${VERSION}';|g" index.html
fi;



cd assets
if [ ! -z ${VERSION} ]; then
    echo "replace base url with ${VERSION}"
    sed -i "s#0#$VERSION#" version.json
fi;

echo "################"
echo "S.T.A.R.T.I.N.G"
echo "################"
cd /app && ./caddy
